<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box" attr="none"></div>
    <script>
        let box = document.querySelector('.box')
        let m = new MutationObserver(function () {
            console.log('变了');
        })
        m.observe(box, {
            attributes: true,
            characterData: true,
            childList: true,
            subtree: true,
            attributeOldValue: true,
            characterDataOldValue: true
        })
        box.setAttribute('attr', 'test')
    </script>
</body>

</html>